<template>
  <div id="setManagement" class="setManagement same-change-oldstyle">
    <div class="same-head-box">
      <div class="saem-seat-box">
        <div class="saem-seat-left">
          <span>当前位置：</span>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>经营管理</el-breadcrumb-item>
            <el-breadcrumb-item>设置管理</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/setManagement' }">设置</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="saem-seat-right">
          <button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button>
        </div>
      </div>
    </div>
    <div class="head_box same-table-box">
      <h4 class="same-title-box">
        积分功能
      </h4>
      <el-switch
        style="display: block"
        v-model="switch_value"
        active-color="#2c5586"
        active-text="开启"
        inactive-text="关闭" @change="switchChange">
      </el-switch>
      <p style="font-size: 12px;color: #808080;margin-top: 10px;">说明:一旦开启后,用户扫码打水时可选择积分打水,并且用户自助充值或者经营者代客充值时以一定比例赠送积分。</p>
    </div>
  </div>
</template>

<script>
    export default {
        name: "setManagement",
      data: function () {
        return {
          switch_value: true,
        }
      },
      created: function () {
        this.getSwitchConfig();
      },
      inject: [
        'reload'
      ],
      methods:{
        RefreshFun() {
          // 调用reload方法，刷新整个页面
          this.reload()
        },
        //获取积分开关配置
        getSwitchConfig(){
          var that = this;
          // ajax请求
          that.$post({
            url: 'Partner/Achievement/getIntegralSetting',
            data: {},
            success: (data) => {
              if (data.code == 1000) {
                that.switch_value = data.data.integral_setting==1?true:false;
              }
            }
          })
        },
        switchChange(e){
          console.log(e)
          var that = this;
          // ajax请求
          that.$post({
            url: 'Partner/Achievement/integralSetting',
            data: {
              set_value: that.switch_value?'1':'2',
            },
            success: (data) => {
              if (data.code == 1000) {
                that.$message({
                  type: "success",
                  showClose: true,
                  message: data.message,
                  center: true
                });
                that.getSwitchConfig();
              } else {
                that.$message({
                  type: "error",
                  showClose: true,
                  message: data.message,
                  center: true
                });
              }
            }
          })
        }
      }
    }
</script>

<style scoped>

</style>
